package com.glory.hikvisionmobile.activity;

import android.content.res.Resources;

import com.glory.hikvisionmobile.R;
import com.glory.hikvisionmobile.base.Constant;
import com.glory.hikvisionmobile.bean.Login.AuthoritysBean;
import com.glory.hikvisionmobile.fragment.PDAEqpFragment;
import com.glory.hikvisionmobile.fragment.PDALotFragment;
import com.glory.hikvisionmobile.fragment.PDAWorkFragment;
import com.glory.hikvisionmobile.fragment.PDAFormFragment;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_TabEntity;
import com.pda.platform.ui.ui_pdaplatform.tablayout.CommonTabLayout;
import com.pda.platform.ui.ui_pdaplatform.tablayout.listener.CustomTabEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ActivityManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import androidx.fragment.app.Fragment;
import butterknife.BindView;

public class HomeActivity extends FreeUI_BaseActivity {
    @BindView(R.id.tabLayout)
    CommonTabLayout tabLayout;

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private ArrayList<Fragment> mFragments = new ArrayList<>();

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_home;
    }

    @Override
    protected void initView() {
        FreeApi_ActivityManager.getActivityManager().addActivity(this);
        dataIntegration();
    }



    @Override
    protected void initData() {

        Resources resources = getResources();

        if(Constant.Jurisdiction.containsKey("PDAWorkFragment"))
        {
            mFragments.add(new PDAWorkFragment());
            mTabEntities.add(new FreeUI_TabEntity("作业管理",
                    resources.getDrawable(R.drawable.hik_work_select), resources.getDrawable(R.drawable.hik_work_unselect)));
        }
        if(Constant.Jurisdiction.containsKey("PDALotFragment"))
        {
            mFragments.add(new PDALotFragment());
            mTabEntities.add(new FreeUI_TabEntity("批次管理",
                    resources.getDrawable(R.drawable.hik_lot_select), resources.getDrawable(R.drawable.hik_lot_unselect)));
        }
        if(Constant.Jurisdiction.containsKey("PDAEqpFragment"))
        {
            mFragments.add(new PDAEqpFragment());
            mTabEntities.add(new FreeUI_TabEntity("设备管理",
                    resources.getDrawable(R.drawable.hik_eqp_select), resources.getDrawable(R.drawable.hik_eqp_unselect)));
        }
        if(Constant.Jurisdiction.containsKey("PDAFormFragment"))
        {
            mFragments.add(new PDAFormFragment());
            mTabEntities.add(new FreeUI_TabEntity("表单管理",
                    resources.getDrawable(R.drawable.hik_form_select), resources.getDrawable(R.drawable.hik_form_unselect)));
        }

        if (mTabEntities != null && mTabEntities.size() > 0) {
            tabLayout.setTabData(mTabEntities, this, R.id.content, mFragments);
        }
    }

    private void dataIntegration()
    {
        if(Constant.LOGIN_BEAN==null)
            return;
        Constant.LOGIN_BEAN.getAuthoritys().forEach(s  ->{
            if(Constant.Jurisdiction.containsKey(s.getTabKey())) {
                Constant.Jurisdiction.get(s.getTabKey()).put(s.getFunctionKey(), s);
            }else{
                Map<String, AuthoritysBean> beanMap = new HashMap<>();
                beanMap.put(s.getFunctionKey(),s);
                Constant.Jurisdiction.put(s.getTabKey(),beanMap);
            }
        });
        System.out.print(Constant.Jurisdiction.size());
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }
}
